﻿using Abp.Domain.Repositories;
using Abp.Reflection.Extensions;
using ARchGL.Platform.Electrocar.Application.Enum;
using ARchGL.Platform.Electrocar.Application.Utils;
using ARchGL.Platform.Electrocar.Application.ViewDtos;
using ARchGL.Platform.Electrocar.Core;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace ARchGL.Platform.Electrocar.Application
{
    /// <summary>
    /// 基础数据初始化
    /// </summary>
    public class Init
    {
        private readonly OfficeHelper<Excels> excelHelper = new OfficeHelper<Excels>();
        private string folderPath;

        public Init()
        {
            folderPath = $"{SystemHelper.GetContentRootFolder()}/wwwroot/Plugins/InitDataExcel/";
            Console.WriteLine(Directory.GetCurrentDirectory() + " - " + folderPath);
        }

        #region 初始化实现

        #region 车身系统

        /// <summary>
        /// 
        /// </summary>
        /// <param name="projectId">项目标识</param>
        /// <returns></returns>
        public async Task<Tuple<List<ModelAssemblys>, List<ModelDirectorys>, List<ModelPropertys>>> CreatePropertys(Guid projectId)
        {
            ProjectId = projectId;
            var directorysId = Guid.NewGuid().ToString().Substring(0, 31);//Guid 后面5位0在方法中累加
            var emptyGuid = "00000000-0000-0000-0000-000000000000";
            string.Intern(directorysId);

            //var propertyId = propertyRootId.Substring(0, 33);//Guid 后面4位0在方法中累加
            //string.Intern(directorysId);

            ModelAssemblysList = new List<ModelAssemblys>();
            ModelDirectorysList = new List<ModelDirectorys>();
            ModelPropertysList = new List<ModelPropertys>();
            modelDirectorysIdCount = 1;
            modelPropertysIdCount = 1;

            var modelDirectorysPath = $"{folderPath}ModelDirectorys.xlsx";
            var bodysList = excelHelper.GetSheetValues(modelDirectorysPath);

            var firIndex = 0;//定位一级总成下标
            var secIndex = 0;//定位二级总成下标
            //循环读取一个sheet中的一行
            foreach (var item in bodysList)
            {
                var processingData = ProcessingData(item, ModelDirectorysList, ref firIndex, ref secIndex);
                if (ProcessingDataType.一级目录 == processingData.Type)
                {
                    await CreateAttachmentRoot(directorysId, int.Parse(processingData.Item.Level), emptyGuid, processingData.Item.Name, string.Empty, int.Parse(processingData.Item.Sort));
                }
                else if (ProcessingDataType.二级目录 == processingData.Type)
                {
                    await CreateAttachmentChild(directorysId, int.Parse(processingData.Item.Level), processingData.Index, processingData.Item.Name, string.Empty, int.Parse(processingData.Item.Sort));
                }
                else
                {
                    await CreateAttachmentChild(directorysId, int.Parse(processingData.Item.Level), processingData.Index, processingData.Item.Name, processingData.Item.Code, int.Parse(processingData.Item.Sort));
                }
                #region 循环处理表格数据(已弃用，转为使用公共方法)
                //循环读取每行中的元素并加入动态数组
                //foreach (var str in item)
                //{
                //    arrayList.Add(str);
                //}
                ////判断是否为一级总成
                //var test = DirectoryType.一级总成.GetHashCode().ToString();
                //if (DirectoryType.一级总成.GetHashCode().ToString() == arrayList[1].ToString())
                //{
                //    var arrString = (string[])arrayList.ToArray(typeof(string));
                //    await CreateAttachmentRoot(directorysId, Convert.ToInt32(arrayList[1]), emptyGuid, arrString[0], string.Empty, Convert.ToInt32(arrayList[2]));
                //    //刷新一级总成下标
                //    if (symbol)
                //    {
                //        firIndex = ModelDirectorysList.Count - 1;
                //    }
                //    if (!symbol)
                //    {
                //        symbol = true;
                //    }
                //    //无二级总成情况下刷新二级总成下标为一级总成下标
                //    secIndex = ModelDirectorysList.Count - 1;
                //}
                ////二级总成
                //else if (DirectoryType.二级总成.GetHashCode().ToString() == arrayList[1].ToString())
                //{
                //    //increment++;
                //    var arrString = (string[])arrayList.ToArray(typeof(string));
                //    await CreateAttachmentChild(directorysId, Convert.ToInt32(arrayList[1]), firIndex, arrString[0], string.Empty, Convert.ToInt32(arrayList[2]));
                //    //刷新二级总成下标
                //    secIndex = ModelDirectorysList.Count - 1;
                //}
                ////零件
                //else
                //{
                //    //increment++;
                //    var arrString = (string[])arrayList.ToArray(typeof(string));
                //    await CreateAttachmentChild(directorysId, Convert.ToInt32(arrayList[1]), secIndex, arrString[0], arrString[3], Convert.ToInt32(arrayList[2]));
                //}
                //arrayList.Clear();
                #endregion
            }
            #region 附件1：汽车模型结构树标准模板(已弃用）

            ////一级总成
            //await CreateAttachmentRoot(directorysId, 1, emptyGuid, "保险杠总成", string.Empty, 1);
            //await CreateAttachmentRoot(directorysId, 1, emptyGuid, "翼子板总成", string.Empty, 2);
            //await CreateAttachmentRoot(directorysId, 1, emptyGuid, "机舱总成", string.Empty, 3);
            //await CreateAttachmentRoot(directorysId, 1, emptyGuid, "发动机盖总成", string.Empty, 4);
            //await CreateAttachmentRoot(directorysId, 1, emptyGuid, "顶盖总成", string.Empty, 5);
            //await CreateAttachmentRoot(directorysId, 1, emptyGuid, "前门总成", string.Empty, 6);
            //await CreateAttachmentRoot(directorysId, 1, emptyGuid, "后门总成", string.Empty, 7);
            //await CreateAttachmentRoot(directorysId, 1, emptyGuid, "地板总成", string.Empty, 8);
            //await CreateAttachmentRoot(directorysId, 1, emptyGuid, "侧围总成", string.Empty, 9);
            //await CreateAttachmentRoot(directorysId, 1, emptyGuid, "行李舱隔板总成", string.Empty, 10);
            //await CreateAttachmentRoot(directorysId, 1, emptyGuid, "行李箱盖/后背门总成", string.Empty, 11);
            //await CreateAttachmentRoot(directorysId, 1, emptyGuid, "后围板总成", string.Empty, 12);

            ////二级总成
            //await CreateAttachmentChild(directorysId, 2, 0, "前保险杠总成", string.Empty, 1);//13
            //await CreateAttachmentChild(directorysId, 2, 0, "后保险杠总成", string.Empty, 2);//14
            //await CreateAttachmentChild(directorysId, 2, 2, "前风窗横梁总成", string.Empty, 1);//15
            //await CreateAttachmentChild(directorysId, 2, 2, "前围板总成", string.Empty, 2);//16
            //await CreateAttachmentChild(directorysId, 2, 2, "前轮罩总成", string.Empty, 3);//17
            //await CreateAttachmentChild(directorysId, 2, 7, "前地板总成", string.Empty, 1);//18
            //await CreateAttachmentChild(directorysId, 2, 7, "后地板总成", string.Empty, 2);//19
            //await CreateAttachmentChild(directorysId, 2, 8, "侧围外板总成", string.Empty, 1);//20
            //await CreateAttachmentChild(directorysId, 2, 8, "侧围加强板总成", string.Empty, 2);//21

            //#region 1.保险杠总成

            //// 1.1 前保险杠总成
            //await CreateAttachmentChild(directorysId, 3, 12, "前保险杠横梁", "MT100-2803011", 1);
            //await CreateAttachmentChild(directorysId, 3, 12, "前保险杠左吸能盒", "MT100-2803013", 2);
            //await CreateAttachmentChild(directorysId, 3, 12, "前保险杠右吸能盒", "MT100-2803014", 3);
            //await CreateAttachmentChild(directorysId, 3, 12, "前保险杠左法兰盘", "MT100-2803015", 4);
            //await CreateAttachmentChild(directorysId, 3, 12, "前保险杠右法兰盘", "MT100-2803016", 5);

            ////1.2 后保险杠总成
            //await CreateAttachmentChild(directorysId, 3, 13, "后保险杠横梁", "MT100-2804011", 1);
            //await CreateAttachmentChild(directorysId, 3, 13, "后保险杠左吸能盒", "MT100-2804013", 2);
            //await CreateAttachmentChild(directorysId, 3, 13, "后保险杠右吸能盒", "MT100-2804014", 3);
            //await CreateAttachmentChild(directorysId, 3, 13, "后保险杠左法兰盘", "MT100-2804015", 4);
            //await CreateAttachmentChild(directorysId, 3, 13, "后保险杠右法兰盘", "MT100-2804016", 5);
            //await CreateAttachmentChild(directorysId, 3, 13, "拖钩座", "MT100-2803012", 6);
            //await CreateAttachmentChild(directorysId, 3, 13, "连接支架", "MT100-2803017", 7);

            //#endregion

            ////2.翼子板总成
            //await CreateAttachmentChild(directorysId, 1, 3, "左/右翼子板", "MT100-8403011", 7);

            //#region 3.1 前风窗横梁总成

            //await CreateAttachmentChild(directorysId, 3, 14, "前风窗横梁上板左拼接板", "MT100-5301011", 1);
            //await CreateAttachmentChild(directorysId, 3, 14, "前风窗横梁上板右拼接板", "MT100-5301011", 2);
            //await CreateAttachmentChild(directorysId, 3, 14, "左铰链支座", "MT100-5301013", 3);
            //await CreateAttachmentChild(directorysId, 3, 14, "右铰链支座", "MT100-5301014", 4);
            //await CreateAttachmentChild(directorysId, 3, 14, "支架一", "MT100-5301015", 5);
            //await CreateAttachmentChild(directorysId, 3, 14, "支架二", "MT100-5301016", 6);
            //await CreateAttachmentChild(directorysId, 3, 14, "前风窗横梁下板", "MT100-5301017", 7);
            //await CreateAttachmentChild(directorysId, 3, 14, "支架三", "MT100-5301018", 8);
            //await CreateAttachmentChild(directorysId, 3, 14, "支架四", "MT100-5301019", 9);
            //await CreateAttachmentChild(directorysId, 3, 14, "前风窗横梁下板加强板", "MT100-5301021", 10);
            //await CreateAttachmentChild(directorysId, 3, 14, "左管梁安装支座一", "MT100-5301023", 11);
            //await CreateAttachmentChild(directorysId, 3, 14, "右管梁安装支座一", "MT100-5301024", 12);
            //await CreateAttachmentChild(directorysId, 3, 14, "左管梁安装支座二", "MT100-5301025", 13);
            //await CreateAttachmentChild(directorysId, 3, 14, "右管梁安装支座二", "MT100-5301026", 14);
            //await CreateAttachmentChild(directorysId, 3, 14, "左管梁安装支座三", "MT100-5301027", 15);
            //await CreateAttachmentChild(directorysId, 3, 14, "右管梁安装支座三", "MT100-5301028", 16);
            //await CreateAttachmentChild(directorysId, 3, 14, "前风窗横梁下板左加强板", "MT100-5301029", 17);
            //await CreateAttachmentChild(directorysId, 3, 14, "前风窗横梁下板右加强板", "MT100-5301031", 18);

            //#endregion

            ////3.2 前围板总成
            //await CreateAttachmentChild(directorysId, 3, 15, "前围板上部", "MT100-5302011", 1);
            //await CreateAttachmentChild(directorysId, 3, 15, "转向管柱座", "MT100-5302012", 2);
            //await CreateAttachmentChild(directorysId, 3, 15, "前围板下部", "MT100-5302013", 3);

            ////3.3 前轮罩总成
            //await CreateAttachmentChild(directorysId, 3, 16, "左前轮罩本体", "MT100-8405013", 1);
            //await CreateAttachmentChild(directorysId, 3, 16, "前悬置支座", "MT100-8405015", 2);
            //await CreateAttachmentChild(directorysId, 3, 16, "加强板一", "MT100-8405017", 3);
            //await CreateAttachmentChild(directorysId, 3, 16, "管束支架", "MT100-8405019", 4);
            //await CreateAttachmentChild(directorysId, 3, 16, "加强板二", "MT100-8405021", 5);
            //await CreateAttachmentChild(directorysId, 3, 16, "左轮罩上梁外板前", "MT100-5402011", 6);
            //await CreateAttachmentChild(directorysId, 3, 16, "左轮罩上梁外板后", "MT100-5402011", 7);
            //await CreateAttachmentChild(directorysId, 3, 16, "左轮罩上梁内板", "MT100-5402013", 8);
            //await CreateAttachmentChild(directorysId, 3, 16, "连接板", "MT100-5402015", 9);
            //await CreateAttachmentChild(directorysId, 3, 16, "左前大灯支架", "MT100-5402017", 10);

            ////4.发动机盖总成
            //await CreateAttachmentChild(directorysId, 2, 3, "发动机盖外板", "MT100-8402011", 1);
            //await CreateAttachmentChild(directorysId, 2, 3, "发动机盖内板", "MT100-8402021", 2);
            //await CreateAttachmentChild(directorysId, 2, 3, "发动机盖加强板一", "MT100-8402022", 3);
            //await CreateAttachmentChild(directorysId, 2, 3, "发动机盖右连接支架", "MT100-8402024", 4);
            //await CreateAttachmentChild(directorysId, 2, 3, "发动机盖左连接支架", "MT100-8402023", 5);
            //await CreateAttachmentChild(directorysId, 2, 3, "发动机盖左铰链支架", "MT100-8402025", 6);
            //await CreateAttachmentChild(directorysId, 2, 3, "发动机盖右铰链支架", "MT100-8402026", 7);
            //await CreateAttachmentChild(directorysId, 2, 3, "发动机盖左铰链", "MT100-8402027", 8);
            //await CreateAttachmentChild(directorysId, 2, 3, "发动机盖右铰链", "MT100-8402028", 9);

            ////5.顶盖总成
            //await CreateAttachmentChild(directorysId, 2, 4, "顶盖本体", "MT100-5701011", 1);
            //await CreateAttachmentChild(directorysId, 2, 4, "顶盖前横梁", "MT100-5701012", 2);
            //await CreateAttachmentChild(directorysId, 2, 4, "顶盖中横梁", "MT100-5701013", 3);
            //await CreateAttachmentChild(directorysId, 2, 4, "顶盖后横梁", "MT100-5701014", 4);

            ////6.前门总成
            //await CreateAttachmentChild(directorysId, 2, 5, "左前门内板", "MT100-6101011", 1);
            //await CreateAttachmentChild(directorysId, 2, 5, "左前门上横梁", "MT100-6101013", 2);
            //await CreateAttachmentChild(directorysId, 2, 5, "左前门防撞梁", "MT100-6101015", 3);
            //await CreateAttachmentChild(directorysId, 2, 5, "左前门窗框", "MT100-6101017", 4);
            //await CreateAttachmentChild(directorysId, 2, 5, "左前门窗框加强梁", "MT100-6101019", 5);
            //await CreateAttachmentChild(directorysId, 2, 5, "左前门玻璃升降槽", "MT100-6101021", 6);
            //await CreateAttachmentChild(directorysId, 2, 5, "左前门铰链上加强板", "MT100-6101023", 7);
            //await CreateAttachmentChild(directorysId, 2, 5, "左前门铰链下加强板", "MT100-6101025", 8);
            //await CreateAttachmentChild(directorysId, 2, 5, "玻璃升降槽连接支架", "MT100-6101027", 9);
            //await CreateAttachmentChild(directorysId, 2, 5, "左前门门锁加强板", "MT100-6101029", 10);
            //await CreateAttachmentChild(directorysId, 2, 5, "左前门加强板", "MT100-6101031", 11);
            //await CreateAttachmentChild(directorysId, 2, 5, "左前门外板", "MT100-6101051", 12);
            //await CreateAttachmentChild(directorysId, 2, 5, "左前门上铰链", "MT100-6101110", 13);
            //await CreateAttachmentChild(directorysId, 2, 5, "左前门下铰链", "MT100-6101130", 14);

            ////7.后门总成
            //await CreateAttachmentChild(directorysId, 2, 6, "左后车门内板", "MT100-6201011", 1);
            //await CreateAttachmentChild(directorysId, 2, 6, "左后车门上横梁", "MT100-6201013", 2);
            //await CreateAttachmentChild(directorysId, 2, 6, "左后车门防撞梁", "MT100-6201015", 3);
            //await CreateAttachmentChild(directorysId, 2, 6, "左后车门上横梁支架", "MT100-6201017", 4);
            //await CreateAttachmentChild(directorysId, 2, 6, "左后车门窗框", "MT100-6201019", 5);
            //await CreateAttachmentChild(directorysId, 2, 6, "左后车门铰链上加强板", "MT100-6201021", 6);
            //await CreateAttachmentChild(directorysId, 2, 6, "左后车门铰链下加强板", "MT100-6201023", 7);
            //await CreateAttachmentChild(directorysId, 2, 6, "左后车门上梁加强板", "MT100-6201025", 8);
            //await CreateAttachmentChild(directorysId, 2, 6, "左后车门门锁扣加强板", "MT100-6201027", 9);
            //await CreateAttachmentChild(directorysId, 2, 6, "左后车门外板", "MT100-6201031", 10);
            //await CreateAttachmentChild(directorysId, 2, 6, "左后车门上铰链", "MT100-6201110", 11);
            //await CreateAttachmentChild(directorysId, 2, 6, "左后车门下铰链", "MT100-6201130", 12);
            //await CreateAttachmentChild(directorysId, 2, 6, "左后车门锁扣", "MT100-6201150", 13);

            //#region 8.地板总成

            ////8.1 前地板总成
            //await CreateAttachmentChild(directorysId, 3, 17, "前地板前部", "MT100-5120011", 1);
            //await CreateAttachmentChild(directorysId, 3, 17, "左前地板本体", "MT100-5120013", 2);
            //await CreateAttachmentChild(directorysId, 3, 17, "右前地板本体", "MT100-5120014", 3);
            //await CreateAttachmentChild(directorysId, 3, 17, "中通道", "MT100-5120015", 4);
            //await CreateAttachmentChild(directorysId, 3, 17, "加强板一", "MT100-MT100-5120016", 5);
            //await CreateAttachmentChild(directorysId, 3, 17, "加强板二", "MT100-5120017", 6);
            //await CreateAttachmentChild(directorysId, 3, 17, "支座一", "MT100-5120018", 7);
            //await CreateAttachmentChild(directorysId, 3, 17, "左前地板加强板", "MT100-5120019", 8);
            //await CreateAttachmentChild(directorysId, 3, 17, "右前地板加强板", "MT100-5120022", 9);
            //await CreateAttachmentChild(directorysId, 3, 17, "左副车架托架前段", "MT100-5120023", 10);
            //await CreateAttachmentChild(directorysId, 3, 17, "左副车架托架后段", "MT100-5120025", 11);
            //await CreateAttachmentChild(directorysId, 3, 17, "右副车架托架前段", "MT100-5120024", 12);
            //await CreateAttachmentChild(directorysId, 3, 17, "右副车架托架后段", "MT100-5120026", 13);
            //await CreateAttachmentChild(directorysId, 3, 17, "左副车架后支座", "MT100-5120027", 14);
            //await CreateAttachmentChild(directorysId, 3, 17, "右副车架后支座", "MT100-5120028", 15);
            //await CreateAttachmentChild(directorysId, 3, 17, "左前纵梁前段", "MT100-8401011", 16);
            //await CreateAttachmentChild(directorysId, 3, 17, "左前悬置安装盒", "MT100-8401013", 17);
            //await CreateAttachmentChild(directorysId, 3, 17, "左前纵梁法兰盘", "MT100-8401015", 18);
            //await CreateAttachmentChild(directorysId, 3, 17, "左前纵梁法兰盘连接板", "MT100-8401017", 19);
            //await CreateAttachmentChild(directorysId, 3, 17, "左前纵梁前段加强板", "MT100-8401019", 20);
            //await CreateAttachmentChild(directorysId, 3, 17, "左前纵梁连接板一", "MT100-8401021", 21);
            //await CreateAttachmentChild(directorysId, 3, 17, "左前悬置安装座", "MT100-8401023", 21);
            //await CreateAttachmentChild(directorysId, 3, 17, "左前纵梁连接板二", "MT100-8401025", 22);
            //await CreateAttachmentChild(directorysId, 3, 17, "左前纵梁中段", "MT100-8401027", 23);
            //await CreateAttachmentChild(directorysId, 3, 17, "左前纵梁后段", "MT100-8401029", 24);
            //await CreateAttachmentChild(directorysId, 3, 17, "左前纵梁后段拼接板", "MT100-8401029", 25);
            //await CreateAttachmentChild(directorysId, 3, 17, "左前座椅加强梁纵梁一", "MT100-5410011", 26);
            //await CreateAttachmentChild(directorysId, 3, 17, "左前座椅加强梁横梁", "MT100-5410013", 27);
            //await CreateAttachmentChild(directorysId, 3, 17, "左前座椅加强梁纵梁二", "MT100-5410015", 28);
            //await CreateAttachmentChild(directorysId, 3, 17, "左固定支座一", "MT100-5410017", 29);
            //await CreateAttachmentChild(directorysId, 3, 17, "左加强板", "MT100-5410019", 30);
            //await CreateAttachmentChild(directorysId, 3, 17, "左固定支座二", "MT100-5410021", 31);
            //await CreateAttachmentChild(directorysId, 3, 17, "左固定支座三", "MT100-5410023", 32);
            //await CreateAttachmentChild(directorysId, 3, 17, "左固定支座四", "MT100-5410025", 33);
            //await CreateAttachmentChild(directorysId, 3, 17, "左门槛梁前段", "MT100-5409011", 34);
            //await CreateAttachmentChild(directorysId, 3, 17, "左门槛梁后段", "MT100-5409013", 35);
            //await CreateAttachmentChild(directorysId, 3, 17, "左门槛梁加强板一", "MT100-5409015", 36);
            //await CreateAttachmentChild(directorysId, 3, 17, "左门槛梁加强板二", "MT100-5409017", 37);
            //await CreateAttachmentChild(directorysId, 3, 17, "左门槛梁安装支架一", "MT100-5409019", 38);
            //await CreateAttachmentChild(directorysId, 3, 17, "左门槛梁安装支架二", "MT100-5409021", 39);
            //await CreateAttachmentChild(directorysId, 3, 17, "左门槛梁安装支架三", "MT100-5409023", 40);
            //await CreateAttachmentChild(directorysId, 3, 17, "左门槛梁安装支架四", "MT100-5409025", 41);

            //#endregion

            //#region 8.2 后地板总成

            //await CreateAttachmentChild(directorysId, 3, 18, "后地板前板", "MT100-5130011", 1);
            //await CreateAttachmentChild(directorysId, 3, 18, "后地板中段", "MT100-5130012", 2);
            //await CreateAttachmentChild(directorysId, 3, 18, "备胎仓", "MT100-5130015", 3);
            //await CreateAttachmentChild(directorysId, 3, 18, "后地板左后板", "MT100-5130013", 4);
            //await CreateAttachmentChild(directorysId, 3, 18, "后地板右后板", "MT100-5130014", 5);
            //await CreateAttachmentChild(directorysId, 3, 18, "备胎固定座", "MT100-5130016", 6);
            //await CreateAttachmentChild(directorysId, 3, 18, "支座一", "MT100-5130017", 7);
            //await CreateAttachmentChild(directorysId, 3, 18, "支座二", "MT100-5130018", 8);
            //await CreateAttachmentChild(directorysId, 3, 18, "左后纵梁前段", "MT100-8404011", 9);
            //await CreateAttachmentChild(directorysId, 3, 18, "右后纵梁前段", "MT100-8404012", 10);
            //await CreateAttachmentChild(directorysId, 3, 18, "左后纵梁后段", "MT100-8404013", 11);
            //await CreateAttachmentChild(directorysId, 3, 18, "右后纵梁后段", "MT100-8404014", 12);
            //await CreateAttachmentChild(directorysId, 3, 18, "左后纵梁连接板", "MT100-8404015", 13);
            //await CreateAttachmentChild(directorysId, 3, 18, "右后纵梁连接板", "MT100-8404016", 14);
            //await CreateAttachmentChild(directorysId, 3, 18, "左后纵梁加强板一", "MT100-8404017", 15);
            //await CreateAttachmentChild(directorysId, 3, 18, "右后纵梁加强板一", "MT100-8404018", 16);
            //await CreateAttachmentChild(directorysId, 3, 18, "左后纵梁加强板二", "MT100-8404021", 17);
            //await CreateAttachmentChild(directorysId, 3, 18, "右后纵梁加强板二", "MT100-8404022", 18);
            //await CreateAttachmentChild(directorysId, 3, 18, "左后纵梁加强板三", "MT100-8404023", 19);
            //await CreateAttachmentChild(directorysId, 3, 18, "右后纵梁加强板三", "MT100-8404024", 20);
            //await CreateAttachmentChild(directorysId, 3, 18, "左后纵梁加强板四", "MT100-8404025", 21);
            //await CreateAttachmentChild(directorysId, 3, 18, "右后纵梁加强板四", "MT100-8404026", 22);
            //await CreateAttachmentChild(directorysId, 3, 18, "左后纵梁连接板", "MT100-8404027", 23);
            //await CreateAttachmentChild(directorysId, 3, 18, "右后纵梁连接板", "MT100-8404028", 24);
            //await CreateAttachmentChild(directorysId, 3, 18, "左后管束支架", "MT100-8404031", 25);
            //await CreateAttachmentChild(directorysId, 3, 18, "右后管束支架", "MT100-8404032", 26);
            //await CreateAttachmentChild(directorysId, 3, 18, "左后悬架支座", "MT100-8404033", 27);
            //await CreateAttachmentChild(directorysId, 3, 18, "右后悬架支座", "MT100-8404034", 28);
            //await CreateAttachmentChild(directorysId, 3, 18, "加强板一", "MT100-8404019", 29);
            //await CreateAttachmentChild(directorysId, 3, 18, "左后纵梁法兰盘", "MT100-8404035", 30);
            //await CreateAttachmentChild(directorysId, 3, 18, "右后纵梁法兰盘", "MT100-8404036", 41);
            //await CreateAttachmentChild(directorysId, 3, 18, "后车架横梁一", "MT100-8404029", 42);
            //await CreateAttachmentChild(directorysId, 3, 18, "后车架横梁左加强板", "MT100-8404037", 43);
            //await CreateAttachmentChild(directorysId, 3, 18, "后车架横梁右加强板", "MT100-8404038", 44);
            //await CreateAttachmentChild(directorysId, 3, 18, "后座椅坐垫左安装座", "MT100-8404041", 45);
            //await CreateAttachmentChild(directorysId, 3, 18, "后座椅坐垫右安装座", "MT100-8404042", 46);
            //await CreateAttachmentChild(directorysId, 3, 18, "后座椅坐垫左安装扣", "MT100-8404043", 47);
            //await CreateAttachmentChild(directorysId, 3, 18, "后座椅坐垫右安装扣", "MT100-8404044", 48);
            //await CreateAttachmentChild(directorysId, 3, 18, "后车架横梁二", "MT100-8404039", 49);
            //await CreateAttachmentChild(directorysId, 3, 18, "后车架横梁左连接支架", "MT100-8404045", 50);
            //await CreateAttachmentChild(directorysId, 3, 18, "后车架横梁右连接支架", "MT100-8404046", 51);
            //await CreateAttachmentChild(directorysId, 3, 18, "儿童座椅安装座", "MT100-8404049", 52);
            //await CreateAttachmentChild(directorysId, 3, 18, "后车架左安装座", "MT100-8404047", 53);
            //await CreateAttachmentChild(directorysId, 3, 18, "后车架右安装座", "MT100-8404048", 54);
            //await CreateAttachmentChild(directorysId, 3, 18, "安全带左安装座", "MT100-8404051", 55);
            //await CreateAttachmentChild(directorysId, 3, 18, "安全带右安装座", "MT100-8404052", 56);
            //await CreateAttachmentChild(directorysId, 3, 18, "左后轮罩本体", "MT100-5122011", 57);
            //await CreateAttachmentChild(directorysId, 3, 18, "左后减震器支座", "MT100-5122013", 58);
            //await CreateAttachmentChild(directorysId, 3, 18, "左后轮罩连接板", "MT100-5122015", 59);
            //await CreateAttachmentChild(directorysId, 3, 18, "左后轮罩连接支架1", "MT100-5122017", 60);
            //await CreateAttachmentChild(directorysId, 3, 18, "左后轮罩连接支架2", "MT100-5122019", 61);
            //await CreateAttachmentChild(directorysId, 3, 18, "左后轮罩连接支架3", "MT100-5122021", 62);
            //await CreateAttachmentChild(directorysId, 3, 18, "左后轮罩连接支架4", "MT100-5122023", 63);

            //#endregion

            //#region 9.侧围总成

            ////9.1 侧围外板总成
            //await CreateAttachmentChild(directorysId, 3, 19, "左侧围外板本体", "MT100-5401011", 1);
            //await CreateAttachmentChild(directorysId, 3, 19, "左侧围外板加强板一", "MT100-5401013", 2);
            //await CreateAttachmentChild(directorysId, 3, 19, "侧围外板连接板", "MT100-5401015", 3);
            //await CreateAttachmentChild(directorysId, 3, 19, "侧围外板后板", "MT100-5401017", 4);
            //await CreateAttachmentChild(directorysId, 3, 19, "左后大灯支座一", "MT100-5401019", 5);
            //await CreateAttachmentChild(directorysId, 3, 19, "左后大灯支座二", "MT100-5401021", 6);
            //await CreateAttachmentChild(directorysId, 3, 19, "左侧围外板加强板二", "MT100-5401023", 7);
            //await CreateAttachmentChild(directorysId, 3, 19, "支架一", "MT100-5401025", 8);
            //await CreateAttachmentChild(directorysId, 3, 19, "支架二", "MT100-5401027", 9);
            //await CreateAttachmentChild(directorysId, 3, 19, "后背门支撑支座一", "MT100-5401029", 10);
            //await CreateAttachmentChild(directorysId, 3, 19, "后背门支撑支座二", "MT100-5401031", 11);

            ////9.2 侧围加强板总成
            //await CreateAttachmentChild(directorysId, 3, 20, "左侧围内板A柱下加强板", "MT100-5403011", 1);
            //await CreateAttachmentChild(directorysId, 3, 20, "左侧围内板A柱上加强板", "MT100-5403013", 2);
            //await CreateAttachmentChild(directorysId, 3, 20, "左侧围内板B柱本体", "MT100-5403015", 3);
            //await CreateAttachmentChild(directorysId, 3, 20, "左侧围内板上边梁加强板", "MT100-5403017", 4);
            //await CreateAttachmentChild(directorysId, 3, 20, "左侧围内板门槛梁加强板", "MT100-5403019", 5);
            //await CreateAttachmentChild(directorysId, 3, 20, "左侧围内板A柱加强板一", "MT100-5403021", 6);
            //await CreateAttachmentChild(directorysId, 3, 20, "左侧围内板A柱加强板二", "MT100-5403023", 7);
            //await CreateAttachmentChild(directorysId, 3, 20, "左侧围内板安全带上安装座", "MT100-5403025", 8);
            //await CreateAttachmentChild(directorysId, 3, 20, "左侧围内板B柱内板下板", "MT100-5403027", 9);
            //await CreateAttachmentChild(directorysId, 3, 20, "左侧围内板安全带下安装座", "MT100-5403029", 10);
            //await CreateAttachmentChild(directorysId, 3, 20, "左侧围内板安全带加强板", "MT100-5403031", 11);
            //await CreateAttachmentChild(directorysId, 3, 20, "左侧围内板门槛梁加强板一", "MT100-5403033", 12);
            //await CreateAttachmentChild(directorysId, 3, 20, "左侧围内板门槛梁加强板二", "MT100-5403035", 13);
            //await CreateAttachmentChild(directorysId, 3, 20, "左侧围内板门槛梁加强板三", "MT100-5403037", 14);
            //await CreateAttachmentChild(directorysId, 3, 20, "左侧围内板A柱下段", "MT100-5403051", 15);
            //await CreateAttachmentChild(directorysId, 3, 20, "左侧围内板A柱加强板三", "MT100-5403053", 16);
            //await CreateAttachmentChild(directorysId, 3, 20, "左侧围内板B柱内板上板", "MT100-5403071", 17);
            //await CreateAttachmentChild(directorysId, 3, 20, "左侧围内板上边梁", "MT100-5403091", 18);
            //await CreateAttachmentChild(directorysId, 3, 20, "左侧围内板A柱内板上板", "MT100-5403093", 19);
            //await CreateAttachmentChild(directorysId, 3, 20, "左侧围内板安装支架一", "MT100-5403095", 20);
            //await CreateAttachmentChild(directorysId, 3, 20, "左侧围内板安装支架二", "MT100-5403097", 21);
            //await CreateAttachmentChild(directorysId, 3, 20, "顶盖前横梁左连接板", "MT100-5403099", 22);
            //await CreateAttachmentChild(directorysId, 3, 20, "左后轮罩连接板", "MT100-5405011", 23);
            //await CreateAttachmentChild(directorysId, 3, 20, "左门槛梁连接板", "MT100-5405013", 24);
            //await CreateAttachmentChild(directorysId, 3, 20, "左侧围C柱连接板", "MT100-5405015", 25);
            //await CreateAttachmentChild(directorysId, 3, 20, "左侧围安全带安装座", "MT100-5405017", 26);
            //await CreateAttachmentChild(directorysId, 3, 20, "左侧围C柱内板下段", "MT100-5405019", 27);
            //await CreateAttachmentChild(directorysId, 3, 20, "左侧围C柱加强板下段", "MT100-5405021", 28);
            //await CreateAttachmentChild(directorysId, 3, 20, "左侧围C柱加强板中段", "MT100-5405023", 29);
            //await CreateAttachmentChild(directorysId, 3, 20, "左侧围C柱加强板上段", "MT100-5405025", 30);
            //await CreateAttachmentChild(directorysId, 3, 20, "顶盖后横梁左连接板", "MT100-5405027", 31);
            //await CreateAttachmentChild(directorysId, 3, 20, "左侧围C柱内板中段", "MT100-5405029", 32);
            //await CreateAttachmentChild(directorysId, 3, 20, "左行李箱支撑板", "MT100-5405031", 33);
            //await CreateAttachmentChild(directorysId, 3, 20, "左行李箱上横梁加强板", "MT100-5405033", 34);
            //await CreateAttachmentChild(directorysId, 3, 20, "行李箱左后板", "MT100-5405035", 35);
            //await CreateAttachmentChild(directorysId, 3, 20, "行李箱左下板", "MT100-5405037", 36);
            //await CreateAttachmentChild(directorysId, 3, 20, "左侧围C柱内板上段", "MT100-5405039", 37);
            //await CreateAttachmentChild(directorysId, 3, 20, "行李箱左上板", "MT100-5405041", 38);
            //await CreateAttachmentChild(directorysId, 3, 20, "行李箱左上横梁内板", "MT100-5405043", 39);

            //#endregion

            //#region 10.行李舱隔板总成

            ////10.行李舱隔板总成
            //await CreateAttachmentChild(directorysId, 3, 9, "行李舱隔板下横梁", "MT100-5603011", 1);
            //await CreateAttachmentChild(directorysId, 3, 9, "行李舱隔板左边梁", "MT100-5603013", 2);
            //await CreateAttachmentChild(directorysId, 3, 9, "行李舱隔板右边梁", "MT100-5603014", 3);
            //await CreateAttachmentChild(directorysId, 3, 9, "后座椅左支撑座", "MT100-5603015", 4);
            //await CreateAttachmentChild(directorysId, 3, 9, "后座椅右支撑座", "MT100-5603016", 5);
            //await CreateAttachmentChild(directorysId, 3, 9, "左连接板", "MT100-5603017", 6);
            //await CreateAttachmentChild(directorysId, 3, 9, "右连接板", "MT100-5603018", 7);
            //await CreateAttachmentChild(directorysId, 3, 9, "后座椅靠背左下安装座", "MT100-5603019", 8);
            //await CreateAttachmentChild(directorysId, 3, 9, "后座椅靠背右下安装座", "MT100-5603022", 9);
            //await CreateAttachmentChild(directorysId, 3, 9, "后座椅靠背左上安装扣", "MT100-5603023", 10);
            //await CreateAttachmentChild(directorysId, 3, 9, "后座椅靠背右上安装扣", "MT100-5603024", 11);
            //await CreateAttachmentChild(directorysId, 3, 9, "后座椅坐垫左后安装扣", "MT100-5603025", 12);
            //await CreateAttachmentChild(directorysId, 3, 9, "后座椅坐垫右后安装扣", "MT100-5603026", 13);

            //#endregion

            //#region 11.后背门总成
            ////11.后背门总成
            //await CreateAttachmentChild(directorysId, 3, 10, "后背门外板上板", "MT100-6301031", 1);
            //await CreateAttachmentChild(directorysId, 3, 10, "后背门外板下板", "MT100-6301032", 2);
            //await CreateAttachmentChild(directorysId, 3, 10, "后背门内板", "MT100-6301011", 3);
            //await CreateAttachmentChild(directorysId, 3, 10, "后背门内板右加强板一", "MT100-6301012", 4);
            //await CreateAttachmentChild(directorysId, 3, 10, "后背门内板左加强板一", "MT100-6301013", 5);
            //await CreateAttachmentChild(directorysId, 3, 10, "后背门中上支撑板", "MT100-6301014", 6);
            //await CreateAttachmentChild(directorysId, 3, 10, "后背门右上支撑板", "MT100-6301016", 7);
            //await CreateAttachmentChild(directorysId, 3, 10, "后背门左上支撑板", "MT100-6301015", 8);
            //await CreateAttachmentChild(directorysId, 3, 10, "后背门内板右加强板二", "MT100-6301018", 9);
            //await CreateAttachmentChild(directorysId, 3, 10, "后背门内板左加强板二", "MT100-6301017", 10);
            //await CreateAttachmentChild(directorysId, 3, 10, "后背门右下支撑板", "MT100-6301022", 11);
            //await CreateAttachmentChild(directorysId, 3, 10, "后背门左下支撑板", "MT100-6301021", 12);
            //await CreateAttachmentChild(directorysId, 3, 10, "后背门内板右加强板三", "MT100-6301024", 13);
            //await CreateAttachmentChild(directorysId, 3, 10, "后背门内板左加强板三", "MT100-6301023", 14);
            //await CreateAttachmentChild(directorysId, 3, 10, "后背门中下支撑板", "MT100-6301025", 15);
            //await CreateAttachmentChild(directorysId, 3, 10, "右后背门支撑板支座", "MT100-6301026", 16);
            //await CreateAttachmentChild(directorysId, 3, 10, "左后背门支撑板支座", "MT100-6301027", 17);
            //await CreateAttachmentChild(directorysId, 3, 10, "后背门铰链", "MT100-6301110", 18);

            //#endregion

            //#region 12. 后围板总成
            ////12. 后围板总成
            //await CreateAttachmentChild(directorysId, 3, 11, "后围板外板", "MT100-5601011", 1);
            //await CreateAttachmentChild(directorysId, 3, 11, "后围板本体", "MT100-5601012", 2);
            //await CreateAttachmentChild(directorysId, 3, 11, "后背门锁加强板", "MT100-5601013", 3);
            //await CreateAttachmentChild(directorysId, 3, 11, "连接支架一", "MT100-5601014", 4);
            //await CreateAttachmentChild(directorysId, 3, 11, "连接支架二", "MT100-5601015", 5);
            //await CreateAttachmentChild(directorysId, 3, 11, "连接支架三", "MT100-5601016", 6);

            //#endregion

            #endregion

            //获取总成属性
            var modelAssemblysPath = $"{folderPath}ModelAssemblys.xlsx";
            var assemblysPropertysList = excelHelper.GetSheetValues(modelAssemblysPath);

            //获取总成列表
            var assemblysList = from ModelDirectorys assembly in ModelDirectorysList where assembly.Level == 1 || assembly.Level == 2 select assembly;
            foreach(var item in assemblysList)
            {
               foreach(var prop in assemblysPropertysList)
                {
                    await AddModelAssemblysList(directorysId, item.ProjectId, item.Id, prop.Name);
                }
            }
            return new Tuple<List<ModelAssemblys>, List<ModelDirectorys>, List<ModelPropertys>>(ModelAssemblysList, ModelDirectorysList, ModelPropertysList);
        }

        #endregion

        public async Task<List<ModelAssemblys>> SetAssemblyPropertys(string directorysId, Guid projectId, Guid directoryId)
        {
            //获取总成属性
            var modelAssemblysPath = $"{folderPath}ModelAssemblys.xlsx";
            var assemblysPropertysList = excelHelper.GetSheetValues(modelAssemblysPath);

            //获取总成列表
            foreach (var prop in assemblysPropertysList)
            {
                await AddModelAssemblysList(directorysId, projectId, directoryId, prop.Name);
            }
            return ModelAssemblysList;
        }
        #region 车身属性

        public Guid ProjectId;
        public List<ModelAssemblys> ModelAssemblysList = new List<ModelAssemblys>();
        public List<ModelDirectorys> ModelDirectorysList = new List<ModelDirectorys>();
        public List<ModelPropertys> ModelPropertysList = new List<ModelPropertys>();
        public int modelDirectorysIdCount = 1;
        public int modelPropertysIdCount = 1;
        public int modelAssbemlysIdCount = 1;

        #region 创建附件1（模型目录）

        private async Task CreateAttachmentRoot(string id, int level, string parentId, string name, string code, int sort)
        {
            await AddModelDirectorysList(id, level, Guid.Parse(parentId), name, code, sort);
        }

        private async Task CreateAttachmentChild(string id, int level, int parentIdIndex, string name, string code, int sort)
        {
            var parentId = ModelDirectorysList[parentIdIndex].Id;
            await AddModelDirectorysList(id, level, parentId, name, code, sort);
        }

        private async Task AddModelAssemblysList(string id, Guid projectId, Guid directoryId, string name)
        {
            var number = (modelAssbemlysIdCount++).ToString().PadLeft(5, '0');
            var modelAssemblys = new ModelAssemblys
            {
                Id = Guid.Parse(id + number),
                ProjectId = projectId,
                ParentId = directoryId,
                Name = name,
                CreationTime = DateTime.Parse("2018-11-20")
            };
            ModelAssemblysList.Add(modelAssemblys);
        }
        private async Task AddModelDirectorysList(string id, int level, Guid parentId, string name, string code, int sort)
        {
            var number = (modelDirectorysIdCount++).ToString().PadLeft(5, '0');

            var modelDirectorys = new ModelDirectorys
            {
                Id = Guid.Parse(id + number),
                ParentId = parentId,
                ProjectId = ProjectId,
                Name = name,
                Code = code,
                Type = string.IsNullOrEmpty(code) ? ModelDirectoryType.总成 : ModelDirectoryType.零件,
                Sort = sort,
                Level = level,
                TenantId = 1,
                CreatorUserId = 1,
                CreationTime = DateTime.Parse("2018-11-20")
            };
            ModelDirectorysList.Add(modelDirectorys);
            if (level == 3)//每个子级都有一套一样的基础属性  （附件2：汽车零部件标准信息模板）
            {
                await SetModelPropertys(id, modelDirectorys.Id);
                //var modelPropertysPath = $"{folderPath}ModelPropertys.xlsx";
                //var bodysList = excelHelper.GetSheetValues(modelPropertysPath);

                //var arrayList = new ArrayList();
                //var firIndex = 0;//定位一级属性下标
                //var secIndex = 0;//定位二级属性下标
                //foreach (var item in bodysList)
                //{
                //    var processingData = ProcessingData(item, ModelPropertysList, ref firIndex, ref secIndex);
                //    if (ProcessingDataType.一级目录 == processingData.Type)
                //    {
                //        await AddModelPropertysList(id, int.Parse(processingData.Item.Level), Guid.Empty, modelDirectorys.Id, processingData.Item.Name, int.Parse(processingData.Item.Sort));
                //    }
                //    else if (ProcessingDataType.二级目录 == processingData.Type)
                //    {
                //        await AddModelPropertysList(id, int.Parse(processingData.Item.Level), ModelPropertysList[processingData.Index].Id, modelDirectorys.Id, processingData.Item.Name, int.Parse(processingData.Item.Sort));
                //    }
                //    #region 循环处理表格数据(已弃用，转为使用公共方法)
                //    ////循环读取每行中的元素并加入动态数组
                //    //foreach (var str in item)
                //    //{
                //    //    arrayList.Add(str);
                //    //}
                //    ////判断是否为父节点
                //    //if (PropertyType.属性类名.GetHashCode().ToString() == arrayList[1].ToString())
                //    //{
                //    //    var arrString = (string[])arrayList.ToArray(typeof(string));
                //    //    await AddModelPropertysList(id, Convert.ToInt32(arrayList[1]), Guid.Empty, modelDirectorys.Id, arrString[0], Convert.ToInt32(arrayList[2]));
                //    //    //刷新父节点下标
                //    //    if (symbol)
                //    //    {
                //    //        index = ModelPropertysList.Count - 1;
                //    //    }
                //    //    if (!symbol)
                //    //    {
                //    //        symbol = true;
                //    //    }
                //    //}
                //    ////非父节点
                //    //else
                //    //{
                //    //    var arrString = (string[])arrayList.ToArray(typeof(string));
                //    //    await AddModelPropertysList(id, Convert.ToInt32(arrayList[1]), ModelPropertysList[index].Id, modelDirectorys.Id, arrString[0], Convert.ToInt32(arrayList[2]));
                //    //}
                //    //arrayList.Clear();
                //    #endregion
                //}
                #region 属性信息标准模板(已弃用)
                ////一级名称
                //var list = new string[] { "基本信息", "化学成分", "物理性能", "工艺信息", "力学性能", "动态性能", "工艺性能", "微观组织", "表面质量", "应用情况" };
                //var rootList = await CreateAttachment2(list, id, 1, Guid.Empty, modelDirectorys.Id);

                ////基本信息1
                //list = new string[] { "材料牌号", "生产厂家", "材料类别", "尺寸规格", "表面状态", "成本信息" };
                //await CreateAttachment2(list, id, 2, rootList[0].Id, modelDirectorys.Id);

                ////元素名称2
                //list = new string[] { "C", "Si", "Mn", "P", "S", "Cr", "Mo", "Ni", "Cu", "Nb", "Ti", "V" };
                //await CreateAttachment2(list, id, 2, rootList[1].Id, modelDirectorys.Id);

                ////物理性能3
                //list = new string[] { "密度（ρ）", "熔点（Tm）", "导热率（λ）", "热膨胀系数（α）", "比热容（C）", "电导率（σ）", "电阻率（ρ）", "电阻温度系数（TCR）", "磁感应强度（B）", "磁场强度（H）", "矫顽力（Hc）", "铁损（P）" };
                //await CreateAttachment2(list, id, 2, rootList[2].Id, modelDirectorys.Id);

                ////工艺信息4
                //await CreateAttachment2(new string[] { "交货状态", "工艺信息" }, id, 2, rootList[3].Id, modelDirectorys.Id);

                ////力学性能5
                //list = new string[] { "屈服强度（Rel）", "抗拉强度（Rm）", "屈强比（Rel / Rm）", "断后延伸率（A）", "断面收缩率（Ψ）", "弹性模量（E）", "形变强化指数（n）", "塑性应变比（r0）", "塑性应变比（r45）", "塑性应变比（r90）", "塑性应变比各向异性度（Δr）", "泊松比（ν）", "准静态拉伸曲线", "高温拉伸性能", "弯曲性能", "洛氏硬度", "布氏硬度", "维氏硬度" };
                //await CreateAttachment2(list, id, 2, rootList[4].Id, modelDirectorys.Id);

                ////动态性能6
                //list = new string[] { "冲击韧性（ak）", "低温脆性（FATT）", "高周疲劳性能", "低周疲劳性能", "高速拉伸性能", "断裂卡片", "延迟断裂性能" };
                //await CreateAttachment2(list, id, 2, rootList[5].Id, modelDirectorys.Id);

                ////工艺性能7
                //list = new string[] { "成形极限（FLD）", "CCT曲线", "摩擦性能", "连接性能", "卷边性能", "扩孔性能（KWI）", "抗凹性能", "胀形性能（IE）", "拉深性能（LDR）", "拉深性能（TZP）", "复合成形性（CCV）", "方形对角拉伸性能（YBT）", "回弹性能", "二次加工脆性", "油漆兼容性", "烘烤硬化性", };
                //await CreateAttachment2(list, id, 2, rootList[6].Id, modelDirectorys.Id);

                ////微观组织8
                //await CreateAttachment2(new string[] { "序号1", "序号2", "序号3" }, id, 2, rootList[7].Id, modelDirectorys.Id);

                ////表面质量9
                //list = new string[] { "镀层类别", "镀层厚度", "镀层重量", "表面粗糙度", "结晶尺寸", "镀层孔隙率", "镀层附着力", "镀层显微硬度", "镀层耐蚀性能", "镀层脆性", "镀层内应力", "镀层外观" };
                //await CreateAttachment2(list, id, 2, rootList[8].Id, modelDirectorys.Id);

                ////应用情况10
                //list = new string[] { "典型应用对象", "当前车型应用情况", "相关标准情况" };
                //await CreateAttachment2(list, id, 2, rootList[9].Id, modelDirectorys.Id);
                #endregion
            }
        }

        #endregion

        public async Task<List<ModelPropertys>> SetModelPropertys(string id, Guid parentId)
        {
            var modelPropertysPath = $"{folderPath}ModelPropertys.xlsx";
            var bodysList = excelHelper.GetSheetValues(modelPropertysPath);

            var arrayList = new ArrayList();
            var firIndex = 0;//定位一级属性下标
            var secIndex = 0;//定位二级属性下标
            foreach (var item in bodysList)
            {
                var processingData = ProcessingData(item, ModelPropertysList, ref firIndex, ref secIndex);
                if (ProcessingDataType.一级目录 == processingData.Type)
                {
                    await AddModelPropertysList(id, int.Parse(processingData.Item.Level), Guid.Empty, parentId, processingData.Item.Name, int.Parse(processingData.Item.Sort));
                }
                else if (ProcessingDataType.二级目录 == processingData.Type)
                {
                    await AddModelPropertysList(id, int.Parse(processingData.Item.Level), ModelPropertysList[processingData.Index].Id, parentId, processingData.Item.Name, int.Parse(processingData.Item.Sort));
                }
            }
            return ModelPropertysList;
        }
        #region 创建附件2（模型属性）
        #region 属性标准模板配套函数(已弃用)
        //private async Task<List<ModelPropertys>> CreateAttachment2(string[] list, string id, int level, Guid parentId, Guid directoryId)
        //{
        //    var modelLsit = new List<ModelPropertys>();
        //    for (int i = 0; i < list.Length; i++)
        //    {
        //        modelLsit.Add(await AddModelPropertysList(id, level, parentId, directoryId, list[0], i + 1));
        //    }
        //    return modelLsit;
        //}
        #endregion

        private async Task<ModelPropertys> AddModelPropertysList(string id, int level, Guid parentId, Guid directoryId, string name, int sort)
        {
            var number = (modelPropertysIdCount++).ToString().PadLeft(5, '0');

            var entity = new ModelPropertys
            {
                Id = Guid.Parse(id + number),
                ParentId = parentId,
                DirectoryId = directoryId,
                ProjectId = ProjectId,
                Name = name,
                Type = 0,
                Sort = sort,
                Level = level,
                TenantId = 1,
                CreatorUserId = 1,
                CreationTime = DateTime.Parse("2018-11-20")
            };

            ModelPropertysList.Add(entity);
            return entity;
        }

        #endregion

        #endregion

        #region 车型级别

        /// <summary>
        /// 初始化车型级别
        /// </summary>
        /// <param name="roodId"></param>
        /// <returns></returns>
        public async Task<List<CarCategorys>> CreateCarCategorys(string roodId)
        {
            var id = roodId.Substring(0, 31);//Guid 后面4位0在方法中累加
            var emptyGuid = "00000000-0000-0000-0000-000000000000";

            CreateCarCategorys(id, "轿车", Guid.Parse(emptyGuid), 1, 1);
            CreateCarCategorys(id, "SUV", Guid.Parse(emptyGuid), 1, 2);
            CreateCarCategorys(id, "MPV", Guid.Parse(emptyGuid), 1, 3);
            CreateCarCategorys(id, "跑车", Guid.Parse(emptyGuid), 1, 4);

            CreateCarCategorys(id, "微型车", CarCategorysList[0].Id, 2, 1);
            CreateCarCategorys(id, "小型车", CarCategorysList[0].Id, 2, 2);
            CreateCarCategorys(id, "紧凑型车", CarCategorysList[0].Id, 2, 3);
            CreateCarCategorys(id, "中型车", CarCategorysList[0].Id, 2, 4);
            CreateCarCategorys(id, "中大型车", CarCategorysList[0].Id, 2, 5);
            CreateCarCategorys(id, "大型车", CarCategorysList[0].Id, 2, 6);

            CreateCarCategorys(id, "小型SUV", CarCategorysList[1].Id, 2, 1);
            CreateCarCategorys(id, "紧凑型SUV", CarCategorysList[1].Id, 2, 2);
            CreateCarCategorys(id, "中型SUV", CarCategorysList[1].Id, 2, 3);
            CreateCarCategorys(id, "中大型SUV", CarCategorysList[1].Id, 2, 4);
            CreateCarCategorys(id, "大型SUV", CarCategorysList[1].Id, 2, 5);

            return CarCategorysList;
        }

        public List<CarCategorys> CarCategorysList = new List<CarCategorys>();
        public int carCategorysIdCount = 1;
        private void CreateCarCategorys(string id, string name, Guid parentId, int level, int sort)
        {
            var number = (carCategorysIdCount++).ToString().PadLeft(5, '0');
            var entity = new CarCategorys
            {
                Id = Guid.Parse(id + number),
                Name = name,
                ParentId = parentId,
                Level = level,
                Sort = sort,
                TenantId = 1,
                CreationTime = DateTime.Parse("2018-11-20")
            };
            CarCategorysList.Add(entity);
        }

        #endregion

        #endregion
        private List<CarBodys> CarbodyList = new List<CarBodys>();
        private string rootId = string.Empty;
        private int carBodysIdCount = 1;
        public async Task<List<CarBodys>> InitCarBodyInfoAsync(Guid projectId)
        {
            rootId = Guid.NewGuid().ToString().Substring(0, 33);//Guid 后面3位0在方法中累加
            var path = $"{folderPath}CarBodys.xlsx";
            var bodysList = excelHelper.GetSheetValues(path);

            var arrayList = new ArrayList();
            var firIndex = 0;//父节点下标
            var secIndex = 0;//子节点下标
            //循环读取一个sheet中的一行
            foreach (var item in bodysList)
            {
                var processingData = ProcessingData(item, CarbodyList, ref firIndex, ref secIndex);
                if (ProcessingDataType.一级目录 == processingData.Type)
                {
                    await AddCarBodys(projectId, int.Parse(processingData.Item.Level), Guid.Empty, processingData.Item.Name, int.Parse(processingData.Item.Sort));
                }
                else if (ProcessingDataType.二级目录 == processingData.Type)
                {
                    await AddCarBodys(projectId, int.Parse(processingData.Item.Level), CarbodyList[processingData.Index].Id, processingData.Item.Name, int.Parse(processingData.Item.Sort));
                }
            }
            ////carBodysRepository.Insert();
            //var path = new string("..\\..\\plugins\\ARchGL.Platform.Electrocar\\Application\\InitDataExcel\\CarBodys.xlsx");
            //var BodysList = new ExcelHelper().ImportExcel(path);
            //var arrayList = new ArrayList();
            //var Count = 0;//父节点下标
            //var increment = 1;//父节点下标增量
            //var Symbol = false;//第一父节点标识，用于跳过第一次父节点下标自增
            ////循环读取一个sheet中的一行
            //foreach (var item in BodysList)
            //{
            //    //跳过首行非可使用数据
            //    if (item != BodysList[0])
            //    {
            //        //循环读取每行中的元素并加入动态数组
            //        foreach (var str in item)
            //        {
            //            arrayList.Add(str);
            //        }
            //        //判断是否为父节点
            //        if (1 == Convert.ToInt32(arrayList[2]))
            //        {
            //            if (Symbol)
            //            {
            //                Count += increment;
            //            }
            //            if (!Symbol)
            //            {
            //                Symbol = true;
            //            }
            //            var arrString = (string[])arrayList.ToArray(typeof(string));
            //            await AddCarBodys(projectId, Convert.ToInt32(arrayList[1]), Guid.Empty, arrString[0], Convert.ToInt32(arrayList[3]));
            //        }
            //        //非父节点
            //        if ((1 != Convert.ToInt32(arrayList[2])))
            //        {
            //            increment++;
            //            var arrString = (string[])arrayList.ToArray(typeof(string));
            //            await AddCarBodys(projectId, Convert.ToInt32(arrayList[1]), CarbodyList[Count].Id, arrString[0], Convert.ToInt32(arrayList[3]));
            //        }
            //        arrayList.Clear();
            //    }
            //}
            //await AddCarBodys(projectId, 1, Guid.Empty, "尺寸信息", 1);
            //await AddCarBodys(projectId, 1, Guid.Empty, "质量信息", 2);
            //await AddCarBodys(projectId, 1, Guid.Empty, "材料信息", 3);
            //await AddCarBodys(projectId, 1, Guid.Empty, "模态/刚度信息", 4);
            //await AddCarBodys(projectId, 1, Guid.Empty, "连接信息", 5);
            //await AddCarBodys(projectId, 1, Guid.Empty, "部件数信息", 6);
            //await AddCarBodys(projectId, 1, Guid.Empty, "轻量化评价信息", 7);
            //await AddCarBodys(projectId, 1, Guid.Empty, "制造信息", 8);
            //await AddCarBodys(projectId, 1, Guid.Empty, "其他信息", 9);

            //var parentId = CarbodyList[0].Id;
            //await AddCarBodys(projectId, 2, parentId, "车身长度", 1);
            //await AddCarBodys(projectId, 2, parentId, "车身宽度", 2);
            //await AddCarBodys(projectId, 2, parentId, "车身高度", 3);
            //await AddCarBodys(projectId, 2, parentId, "前轮距", 4);
            //await AddCarBodys(projectId, 2, parentId, "后轮距", 5);
            //await AddCarBodys(projectId, 2, parentId, "轴距", 6);
            //await AddCarBodys(projectId, 2, parentId, "投影面积（=（（前轮距+后轮距）/2）*轴距）", 7);

            //parentId = CarbodyList[1].Id;
            //await AddCarBodys(2, parentId, "车身总质量（含四门两盖+保险杠+副车架等所有车身附件，不喷漆）", 1);
            //await AddCarBodys(2, parentId, "前副车架质量", 2);
            //await AddCarBodys(2, parentId, "后副车架质量", 3);
            //await AddCarBodys(2, parentId, "前端模块质量", 4);
            //await AddCarBodys(2, parentId, "车身骨架质量（不含四门两盖+保险杠+副车架等所有车身附件，不喷漆）", 5);
            //await AddCarBodys(2, parentId, "前门质量（两个）", 6);
            //await AddCarBodys(2, parentId, "后门质量（两个）", 7);
            //await AddCarBodys(2, parentId, "翼子板质量（两个）", 8);
            //await AddCarBodys(2, parentId, "发动机罩盖质量", 9);
            //await AddCarBodys(2, parentId, "行李箱盖质量", 10);
            //await AddCarBodys(2, parentId, "铰链/紧固件质量", 11);

            return CarbodyList;
        }

        ///添加车身数据
        private async Task AddCarBodys(Guid projectId, int level, Guid parentId, string name, int sort)
        {
            var number = carBodysIdCount++.ToString().PadLeft(3, '0');

            var entity = new CarBodys
            {
                Id = Guid.Parse(rootId + number),
                ParentId = parentId,
                ProjectId = projectId,
                Name = name,
                Sort = sort,
                Level = level,
                TenantId = 1,
                CreatorUserId = 1,
                CreationTime = DateTime.Parse("2018-11-20")
            };
            CarbodyList.Add(entity);
        }

        /// <summary>
        /// 处理Excel数据公共方法，适用于前两列为Name、Level的三级及三级目录以下表格
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="item">行数据</param>
        /// <param name="dataList">实体存放列表</param>
        /// <param name="firIndex">一级目录下标</param>
        /// <param name="secIndex">二级目录下标</param>
        /// <returns></returns>
        public ProcessingDataDto ProcessingData<T>(Excels item, List<T> dataList, ref int firIndex, ref int secIndex)
        {
            var processingDataDto = new ProcessingDataDto();
            //判断是否为一级目录
            if (ProcessingDataType.一级目录.GetHashCode().ToString() == item.Level)
            {
                //刷新一级目录下标
                firIndex = dataList.Count;
                //无二级目录情况下刷新二级目录下标为一级目录下标
                secIndex = dataList.Count;
                processingDataDto.Item = item;
                processingDataDto.Type = ProcessingDataType.一级目录;
            }
            //二级目录
            else if (ProcessingDataType.二级目录.GetHashCode().ToString() == item.Level)
            {
                //刷新二级目录下标
                secIndex = dataList.Count;
                processingDataDto.Item = item;
                processingDataDto.Index = firIndex;
                processingDataDto.Type = ProcessingDataType.二级目录;
            }
            //三级目录
            else
            {
                processingDataDto.Item = item;
                processingDataDto.Index = secIndex;
                processingDataDto.Type = ProcessingDataType.三级目录;
            }
            return processingDataDto;
        }
    }
}
